package com.hc.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


import com.hc.comm.CommData;

public class SystemConfigUtil {


	
	public static final String FILEPATH= CommData.systemPath+"config\\systemConfig.properties";
	
	public static void readConfig(){
		
		
	File file = new File(FILEPATH);
		
		FileReader fileReader = null;

			try {
				fileReader = new  FileReader(file);
			} catch (FileNotFoundException e1) {
					e1.printStackTrace();
			}
			BufferedReader reader = new BufferedReader(fileReader);
			String linStr = "";
			

			
			try {
				while((linStr=reader.readLine())!=null){
					
				String[] results= 	linStr.split("=");
					
					if("dataBaseIp".equals(results[0])){
						
						BaseSql.ip=results[1];
						
					}else if("port".equals(results[0])){
						
						BaseSql.port=results[1];
						
					}else if("userName".equals(results[0])){
						BaseSql.userName=results[1];
						
					}else if("pwd".equals(results[0])){
						
						BaseSql.pwd= results[1];
					}else if("databaseName".equals(results[0])){
						
						BaseSql.DataName = results[1];
						
					}else if("webTestNumber".equals(results[0])){
						
						CommData.webTestNumber = Integer.parseInt(results[1]);
						
					}else if("radiusIp".equals(results[0])){
						
						CommData.radiusIp = results[1];
						
					}else if("radiusPort".equals(results[0])){
						
						CommData.radiusPort = Integer.parseInt(results[1]);
					}else if("radiusNumber".equals(results[0])){
						
						CommData.radiusNumber = results[1];
						
					}else if("radiusPwd".equals(results[0])){
						
						CommData.radiusPwd =results[1];
					}else if("downFileUrl".equals(results[0])){
						
						CommData.downFileUrl =results[1];
					}
					
					
				}
				
				reader.close();
				fileReader.close();
			} catch (IOException e) {
					e.printStackTrace();
			}


	}
	
	public static void writeConfig(){
		StringBuilder sb = new StringBuilder();

		sb.append("dataBaseIp=").append(BaseSql.ip).append("\r\n");
		sb.append("port=").append(BaseSql.port).append("\r\n");
		sb.append("userName=").append(BaseSql.userName).append("\r\n");
		sb.append("pwd=").append(BaseSql.pwd).append("\r\n");
		sb.append("databaseName=").append(BaseSql.DataName).append("\r\n");
		sb.append("webTestNumber=").append(CommData.webTestNumber).append("\r\n");
		sb.append("radiusIp=").append(CommData.radiusIp).append("\r\n");
		sb.append("radiusPort=").append(CommData.radiusPort).append("\r\n");
		sb.append("radiusNumber=").append(CommData.radiusNumber).append("\r\n");
		sb.append("radiusPwd=").append(CommData.radiusPwd).append("\r\n");
		sb.append("downFileUrl=").append(CommData.downFileUrl).append("\r\n");

		
		File file = new File(FILEPATH);
		FileWriter w;
		try {
			w = new FileWriter(file);
			w.write(sb.toString());
			w.flush();
			w.close();
		} catch (IOException e) {
			e.printStackTrace();
			
		}
	
	

	}
	public static void main(String[] args) {
	
		SystemConfigUtil.readConfig();
		SystemConfigUtil.writeConfig();
	
	}

}
